package ${package.Controller};

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${table.entityName};
import zhp.github.tool.common.model.BaseBean;
import zhp.github.tool.common.model.RS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>
import java.util.List;
import lombok.Setter;

import static zhp.github.tool.common.model.success;

/**
 * ${table.comment!}
 *
 * @author ${author}
 * @since ${date}
 */
@Setter(onMethod_ = {@Autowired})
@RestController
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath?uncap_first}</#if>")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>
</#if>
    private ${table.serviceName} ${table.serviceName?uncap_first};

    /**
     * ${table.comment!}查询
     *
     * @param ${table.entityName?uncap_first} 条件
     * @return 记录
     */
    @PostMapping("query")
    public RS<${table.entityName}> query(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return success(${table.serviceName?uncap_first}.query(${table.entityName?uncap_first}));
    }

    /**
     * ${table.comment!}分页
     *
     * @param query 查询参数
     * @return 分页数据
     */
    @PostMapping("page")
    public RS${r'<'}Page<${table.entityName}>> paging(@RequestBody BaseBean${r'<'}${entity}> query) {
        return success(${table.serviceName?uncap_first}.paging(query));
    }
    /**
     * ${table.comment!}列表
     *
     * @param ${table.entityName?uncap_first} 查询条件
     * @return 列表
     */
    @PostMapping("list")
    public RS${r'<'}List<${table.entityName}>> listWithCond(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return success(${table.serviceName?uncap_first}.listWithCond(${table.entityName?uncap_first}));
    }

    /**
     * ${table.comment!}删除
     *
     * @param ${table.entityName?uncap_first} 参数
     * @return 影响条数
     */
    @DeleteMapping("delete")
    public RS${r'<'}Integer> deleteWithCond(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return success(${table.serviceName?uncap_first}.deleteWithCond(${table.entityName?uncap_first}));
    }

    /**
     * ${table.comment!}更新
     *
     * @param ${table.entityName?uncap_first} 入参
     * @return 影响条数
     */
    @PutMapping("update")
    public RS${r'<'}Boolean> updateOne(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return success(${table.serviceName?uncap_first}.saveOrUpdate(${table.entityName?uncap_first}));
    }

    /**
     * 保存${table.comment!}
     *
     * @param ${table.entityName?uncap_first} 参数
     * @return 影响条数
     */
    @PostMapping("save")
    public RS${r'<'}Boolean> save(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return success(${table.serviceName?uncap_first}.save(${table.entityName?uncap_first}));
    }

    /**
     * 批量保存${table.comment!}
     *
     * @param ${table.entityName?uncap_first} 参数
     * @return 影响条数
     */
    @PostMapping("batchSave")
    public RS${r'<'}Boolean> batchSave(@RequestBody BaseBean${r'<'}List${r'<'}${table.entityName}>> ${table.entityName?uncap_first}) {
        return success(${table.serviceName?uncap_first}.saveBatch(${table.entityName?uncap_first}.getLoad()));
    }
}
